<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>json test</title>
</head>
<body>
<script type="text/javascript">
  //在javascript语言中怎么创建一个json对象
  var user = {
        "usercode" : 111,
        "username" : "zhangsan",
        "sex" : "true",
        "age" : 21,
        "hobby" : ["draw","tour","sweet"],
        "addr" : address
      // "addr" : {"city" : "北京","street" : "大兴区","zipcode" : "1111"}
  }

  var address = {
      "city" : "北京",
      "street" : "大兴区",
      "zipcode" : "1111"
  }
  //怎么访问json对象的属性

  // 第一种方式
  console.log(user.username)
  console.log(user.age)
  console.log(user.sex ? "男" : "女")
  for(var i = 0; i < user.hobby.length; i++){
      console.log(user.hobby[i]);
  }
  console.log(user.addr.street)


  //第二种方式
  console.log(user["username"])
  console.log(user["age"])
  console.log(user["sex"] ? "男" : "女")

</script>
</body>
</html>